package game.block;

import game.block.device.Device;
import game.block.device.DevicePC;
import game.block.game.GameState;
import game.block.sound.IAudio;
import game.block.sound.NullAudio;

import java.util.ArrayList;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;

public class Locator implements Constants {
	private static IAudio audioService;
	private static NullAudio nullService;
	private static ArrayList<ParticleEffect> effects;
	private static InputMultiplexer multi;
	private static Device device;
	private static Game game;
	private static int maxLevel;
	private static int level;
	private static GameState gameState;

	public static void init(Game g, int maxL) {
		nullService = new NullAudio();
		audioService = nullService;
		effects = new ArrayList<ParticleEffect>();
		multi = new InputMultiplexer();
		game = g;
		level=maxL;
		maxLevel=maxL;
	}

	public static void win() {
		writeSave();
		audioService.stopMusic();
	}

	public static void writeSave() {
		Preferences prefs = Gdx.app.getPreferences("My Preferences");
		prefs.putInteger("MaxLevel", maxLevel);
		prefs.flush();
	}
	
	public static void nextLevel(){
	    increaseLevel();
	    Locator.writeSave();
	}
	
	public static void increaseLevel(){
	    level++;
	    if(level > maxLevel){
	        maxLevel++;
	    }
	}

	public static void provideDevice(Device d) {
		if (d == null) {
			device = new DevicePC();
		}
		device = d;
	}

	public static void provideAudio(IAudio service) {
		if (service == null) {
			// use null audio
			audioService = nullService;
		} else {
			audioService = service;
		}
	}
	
	public static void provideGameState(GameState gs){
		gameState=gs;
	}
	public static GameState getGameState(){
		return gameState;
	}

	public static int getLevel() {
        return level;
    }

    public static void setLevel(int level) {
        Locator.level = level;
    }

    public static int getMaxLevel() {
        return maxLevel;
    }

    public static void setMaxLevel(int maxLevel) {
        Locator.maxLevel = maxLevel;
    }

    public static void clearData() {
    	maxLevel=level=1;
	}

	public static InputMultiplexer getInputMultiplexer() {
		return multi;
	}

	public static IAudio getAudio() {
		return audioService;
	}

	public static ArrayList<ParticleEffect> getEffects() {
		return effects;
	}

	public static Device getDevice() {
		return device;
	}

	public static Game getGame() {
		return game;
	}

}
